package com.zhdl.modules.process;

import com.zhdl.modules.common.logging.service.OptRecordService;
import com.zhdl.modules.demo.DCHTProcess.DCTMainProcess;
import com.zhdl.modules.demo.aoptest.OptLog;
import com.zhdl.modules.demo.entity.MachineConf;
import com.zhdl.modules.demo.testprocess.TestMainProcess;
import com.zhdl.modules.demo.testprocess.TestProcessInit;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 此类持有项目主流程管理类 外部通过此类控制主流程 开始 暂停 急停等操作
 */
@Service
public class ProcessStatusExchangeHolder {
    @Resource
    TestMainProcess baseProcess;
//    @Resource
//    DCTMainProcess baseProcess;
    @Resource
    OptRecordService optRecordService;
    public static MachineConf machineConf;
//    @Resource
//    TestTimeOutProcess baseProcess;
    public boolean isStart = false, isRunning = false, initComplete = false, isStop = false;
    public BaseProcess getBaseProcess() {
        return baseProcess;
    }
    @OptLog(title = "开机初始化")
    public void init(){
        baseProcess.initHardware();
      //  optRecordService.saveRecords("开机初始化");
        machineConf = new MachineConf(this);
    }


    @OptLog(title = "初始化位置")
    public void initLocation(){
        baseProcess.initLocation(s -> {
            baseProcess.statusHolder.initComplete = true;
        });
    }
    @OptLog(title = "程序启动")
    public void start(){
        optRecordService.saveRecords("程序启动");
        isStart = baseProcess.statusHolder.start();
    }
    public void stop() {
        baseProcess.statusHolder.stop();
    }
    @OptLog(title = "程序停止")
    public void onPause() {
        baseProcess.statusHolder.stop();
        optRecordService.saveRecords("程序停止");
    }
    @OptLog(title = "程序急停")
    public void release() {
        baseProcess.statusHolder.release();
    }

    public void setAuto(boolean b) {
        baseProcess.statusHolder.setAuto(b);
        optRecordService.saveRecords("手自动切换"+b);
    }
    @OptLog(title = "手动清除所有报警")
    public void cancelAlarm() {
        baseProcess.statusHolder.reset();
    }
    @OptLog(title = "调试模式切换")
    public void switchTest(boolean test){
        baseProcess.statusHolder.setTestModel(test);
    }
}
